package com.necsv;

import java.util.List;

import Util.ShareRefUtil;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.necsv.Mylog.Mylog;

public class ShareToFacebookActivity extends Activity{
	private EditText edtSub;
	private EditText edtContent;
	Context context;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		GoogleAnaTool.trackPage("/ShareToFacebookActivity");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.share_to_facebook);
		edtSub = (EditText)findViewById(R.id.edtSubFb);
		edtContent = (EditText)findViewById(R.id.edtContentFb);
		context = getBaseContext();
		//ShareRefUtil.CleanPre(context);
		ShareRefUtil.Remove(context, "sonnt");
		Log.v("TAG", ShareRefUtil.getPref(context, "sonnt", "Defsonnt"));
		Log.v("TAG", ShareRefUtil.getPref(context, "key", "Defsonnt"));
		ShareRefUtil.setPref(context, "sonnt", "Huyen Dinh");
		ShareRefUtil.setPref(context, "key", "Huyen Dinh");
		Log.v("TAG", ShareRefUtil.getPref(context, "sonnt", "Defsonnt"));
		Log.v("TAG", ShareRefUtil.getPref(context, "key", "Defsonnt"));
	}
	
	public void btn_onClick(View v)
	{
		GoogleAnaTool.trackEvent("shareclick", "click", "share", 1);
		Mylog.Toat(getBaseContext(), "Thanh Son");
		Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
		shareIntent.setType("text/plain");
		shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject123");
		shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://vnexpress.net");
		PackageManager pm = v.getContext().getPackageManager();
		List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
		for (final ResolveInfo app : activityList) {
		    if ((app.activityInfo.name).contains("facebook")) {
		        final ActivityInfo activity = app.activityInfo;
		        final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
		        shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
		        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |             Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
		        shareIntent.setComponent(name);
		        v.getContext().startActivity(shareIntent);
		        break;
		   }
		}
	}
}
